home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / LL_LAND.ZIP / LL_KEY.INC < prev    next >
Text File  |  1993-05-10  |  6KB  |  181 lines

  1. ;; *************************************************************************
  2. ;; LL_KEY.INC   -   Lord Logic's  Keyboard Interupt  Routines  -  LL_KEY.ASM
  3. ;;          - PRIMOR ViDeO GFX Engine v1.2 * Copyright (C) 1992-93 -
  4. ;;
  5. ;; No docs or nfo written for these routines yet.  Given with LL_LAND as a
  6. ;; programming example.  Focus of the example is the 3D Landscape, and not
  7. ;; these routines.  They are pretty straight forward and easy to figure out.
  8. ;;
  9. ;; *************************************************************************
  10. .data
  11. MM      equ     6
  12. public  LL_KEYFLAG
  13. public  LL_KEYBUF
  14. public  LL_KEYCHANGE
  15.  
  16.     LL_KEYFLAG      db      256 dup (0)
  17.     LL_KEYBUF       db      0
  18.     LL_BUF          db      256 dup (0)
  19.     LL_KEYHEAD      dw      offset LL_BUF
  20.     LL_KEYTAIL      dw      offset LL_BUF
  21.     LL_KEYCHANGE    db      0
  22.  
  23.     OLD_9_O dw      offset NEW_9
  24.     OLD_9_S dw      @code
  25.  
  26. .code
  27. ll_keyhit       proc
  28.     push    ds
  29.  
  30.     mov     ax,@data
  31.     mov     ds,ax
  32.  
  33.     xor     ax,ax
  34.     mov     bx,LL_KEYTAIL
  35.     cmp     bx,LL_KEYHEAD
  36.     je      llkh_e
  37.  
  38.     mov     ax,1
  39.  
  40. llkh_e: pop     ds
  41.     ret
  42. ll_keyhit       endp
  43.  
  44. ll_keyget       proc
  45.     push    ds
  46.  
  47.     mov     ax,@data                ;; Set up OUR DATA SEGMENT!
  48.     mov     ds,ax                   ;; :
  49.  
  50.     xor     ax,ax                   ;; Set NO RETURN FLAG
  51.     cmp     LL_KEYBUF,0             ;; Check if the buffer is ACTIVE
  52.     je      llkg_e                  ;; : If not, then exit . . .
  53.  
  54. llkg_1: call    ll_keyhit               ;; No keys in LL_BUF, so we will
  55.     or      ax,ax                   ;; : wait until a key is hit.
  56.     jz      llkg_1                  ;; :
  57.  
  58.     cli
  59.     mov     bx,LL_KEYTAIL           ;; Get a key from the buffer. FIFO
  60.     mov     al,[bx]                 ;; :
  61.     inc     bx                      ;; And update the pointers . . .
  62.  
  63.     cmp     bx,offset LL_BUF+255    ;;
  64.     jne     llkg_2
  65.         mov     bx,offset LL_BUF
  66.  
  67. llkg_2: cmp     bx,LL_KEYHEAD           ;; :
  68.     jne     llkg_3                  ;; Are there any keys left in BUF?
  69.  
  70.     mov     LL_KEYCHANGE,0          ;; : No? -> Clear the CHANGE FLAG
  71.  
  72. llkg_3: mov     LL_KEYTAIL,bx           ;; Update LL_KEYTAIL to new setting.
  73.  
  74. llkg_e: sti                             ;; Interrupts are fine now.
  75.     pop     ds
  76.     xor     ah,ah
  77.     ret
  78. ll_keyget       endp
  79.  
  80. ;; *************************************************************************
  81. ;; void ll_keyswap();
  82. ;; ll_keyswap swaps between the original keyboard interrupt and our new and
  83. ;; improved interrupt.
  84. ;; *************************************************************************
  85. ll_keyswap      proc
  86.     push    ds
  87.     push    es
  88.  
  89.     mov     ax,@data
  90.     mov     ds,ax
  91.  
  92.     mov     ax,03509h       ;; Get interrupt 09h
  93.     int     21h             ;; : return in ES:BX
  94.  
  95.     mov     ax,OLD_9_S
  96.     mov     dx,OLD_9_O
  97.         push    ds
  98.         mov     ds,ax
  99.     mov     ax,02509h       ;; Set new interrupt
  100.     int     21h             ;; : to address in DS:DX
  101.         pop     ds
  102.  
  103.     mov     OLD_9_S,es      ;; Save the old interrupt
  104.     mov     OLD_9_O,bx
  105.  
  106.     pop     es
  107.         pop     ds
  108.         ret
  109. ll_keyswap      endp
  110.  
  111. ;; *************************************************************************
  112. ;; NEW_9() is the new keyboard interrupt.
  113. ;; It reads the scan code from the keyboard and modifies the flags table.
  114. ;; If LL_KEYBUF is set to ON (1) it also places the key in the buffer.  Up
  115. ;; to 255 keys may be placed in the buffer.
  116. ;;
  117. ;; The flag table is set as follows:  The high byte is set to the position
  118. ;; of the key, pressed=1, release=0.  The low byte is set to 1 when the key
  119. ;; is pressed and left unmodified when the key is released.
  120. ;; *************************************************************************
  121. NEW_9   proc    far
  122.         push    ax
  123.         push    bx
  124.     push    di
  125.         push    ds
  126.  
  127.     mov     ax,@data        ;; Set up to point to our DATA Segment
  128.     mov     ds,ax           ;; :
  129.  
  130.     in      ax,60h          ;; Get SCAN CODE in AL, CONTROL in AH
  131.     mov     bx,ax           ;; Save a copy in BX
  132.     xchg    ah,al           ;; Put CONTROL in AL
  133.     or      al,80h          ;; Clear Keyboard of interrupt request
  134.     out     61h,al          ;; :
  135.     and     al,7Fh          ;; :
  136.     out     61h,al          ;; :
  137.     mov     al,20h          ;; Send generic EOI to PIC
  138.     out     20h,al          ;; :
  139.  
  140.     and     bx,0007fh       ;; Strip all but the scan code
  141.     shl     bx,1            ;; Multiply by two to get our offset
  142.  
  143.     test    ah,10000000b    ;; Check if key was RELEASED
  144.     jnz     n9_4            ;; Yes?-> Act accordingly . . .
  145.  
  146.     mov     byte ptr [offset LL_KEYFLAG+BX],1   ;; Key HAS BEEN PRESSED
  147.     mov     byte ptr [offset LL_KEYFLAG+BX+1],1 ;; Key IS BEING PRESSED
  148.     shr     bx,1            ;; Set back to normal number
  149.  
  150.     cmp     LL_KEYBUF,0     ;; Is our KEYBOARD BUFFER ON?
  151.     je      n9_e            ;; : No? -> Continue as normal
  152.  
  153.         mov     di,LL_KEYHEAD   ;; Check if BUFFER is FULL
  154.     cmp     di,offset LL_BUF+255
  155.         jne     n9_2
  156.         cmp     LL_KEYTAIL,offset LL_BUF
  157.     jne     n9_3
  158.         jmp     n9_e
  159.  
  160. n9_2:   inc     di              ;; :
  161.         cmp     LL_KEYTAIL,di   ;; :
  162.     je      n9_e            ;; : Yes?-> Don't put in buffer then.
  163.     dec     di              ;; :
  164.  
  165. n9_3:   mov     [di],bl         ;; Put key in BUFFER
  166.     inc     LL_KEYHEAD      ;; Increment the HEAD needs to loop . . .
  167.     cmp     LL_KEYHEAD,offset LL_BUF+255
  168.     jne     n9_e
  169.     mov     LL_KEYHEAD,offset LL_BUF
  170.     jmp     n9_e            ;; We're done pretty much now . . .
  171.  
  172. n9_4:   mov     byte ptr [offset LL_KEYFLAG+BX+1],0 ;; Key IS RELEASED
  173.  
  174. n9_e:   mov     LL_KEYCHANGE,1
  175.     pop     ds
  176.     pop     di
  177.     pop     bx
  178.     pop     ax
  179.         iret
  180. NEW_9   endp
  181.